#ifndef _OPENGL_BUFFER_H
#define _OPENGL_BUFFER_H

#include "engine.h"

namespace engine
{

    class VertexBuffer
    {
    public:
        VertexBuffer(const void *vertices, uint32_t size);
        VertexBuffer(GLfloat *vertices, GLsizei size);
        ~VertexBuffer();

        void bind();
        void unbind();

        void setData(uint32_t offset, uint32_t size, const void *data);

        // void setLayout(const BufferLayout &layout) override;
        // const BufferLayout &GetLayout() const override;

    private:
        GLuint vbo = 0;
    };

    class IndexBuffer
    {
    public:
        IndexBuffer(const uint32_t *indices, uint32_t size);
        IndexBuffer(GLuint *indices, GLsizei size);
        ~IndexBuffer();

        void bind();
        void unbind();

        void setData(uint32_t offset, uint32_t size, const void *data);

    private:
        GLuint ibo = 0;
    };

    class VertexArray
    {
    public:
        // static GLenum ShaderDataType2OpenGLType(ShaderDataType type);

        VertexArray();
        ~VertexArray();

        void addVertexBuffer(VertexBuffer *buffer, GLint index, GLint length);
        void addIndexBuffer(IndexBuffer *buffer);

        void bind();
        void unbind();

    private:
        GLuint vao = 0;
        std::vector<VertexBuffer *> vertexBuffers; // 顶点数据，本来可以用layout指定不同的数据，现在临时先全部单独搞
        std::vector<IndexBuffer *> indexBuffers;   // 顶点顺序
    };

    class FrameBuffer
    {
    public:
        FrameBuffer();
        ~FrameBuffer();

        void bind();
        void unbind();

        GLuint get_texture();

    private:
        GLuint fbo = 0;
        GLuint textureColor = 0;
    };

}

#endif
